from base.java.exception.UnsupportedOperationException import UnsupportedOperationException
from base.util.iterator.ExtendedIterator import ExtendedIterator
from inspect import isfunction

'''
传进来一个function 调用next的时候，在原来的next的基础上，再调用一下这个function
'''


class Map1Iterator(ExtendedIterator):

    def __init__(self, func, base):
        if not isfunction(func):
            raise UnsupportedOperationException('first param must be a function')

        self.func = func
        self.base = base

    def next(self):
        self.func(self.base.next())

    def hasNext(self):
        return self.base.hasNext()

    def remove(self):
        return self.base.remove()

    def close(self):
        return self.base.close()
